<template>
    <div>
        <Modal width="820"
               v-model="modal.addTeacherFlag"
               @on-cancel="cancel"
               title="添加教师">
            <div class="modalDiv"></div>
            <Form ref="teacher" :model="teacher" :rules="ruleValidate" inline :label-width="100">
                <FormItem prop="worker" label="工号">
                    <Input class="myform" v-model="teacher.worker" clearable/>
                </FormItem>
                <FormItem prop="name" label="名称">
                    <Input class="myform" v-model="teacher.name" clearable/>
                </FormItem>
                <FormItem prop="sex" label="性别">
                    <Select v-model="teacher.sex" clearable class="myform">
                        <Option value="男">男</Option>
                        <Option value="女">女</Option>
                    </Select>
                </FormItem>
                <FormItem prop="birthday" label="出生年月日">
                    <DatePicker class="myform" type="date" v-model="teacher.birthday" clearable/>
                </FormItem>
                <FormItem prop="position" label="职称">
                    <Input class="myform" v-model="teacher.position" clearable/>
                </FormItem>
                <FormItem prop="collegeId" label="学院">
                    <Select v-model="teacher.collegeId" clearable class="myform">
                        <Option  v-for="item in modal.list" :value="item.collegeId" :key="item.collegeId">{{item.name}}</Option>
                    </Select>
                </FormItem>
            </Form>
            <Button type="primary" slot="footer" @click="ok" :loading="loading">提交</Button>
        </Modal>
    </div>
</template>

<script>
    import {AddTeacherRuleValidate} from '../ruleValidate'

    export default {
        name: "addTeacher",
        props: {
            modal: {
                addTeacherFlag: false,
                list:[]
            }
        },
        data() {
            return {
                loading: false,
                ruleValidate: AddTeacherRuleValidate(),
                teacher: {},
            }
        },
        methods: {
            ok() {
                this.$refs["teacher"].validate((valid) => {
                    if (valid) {
                        alert("111")
                        this.loading = true
                        this.teacher.birthday = new Date(this.teacher.birthday).toLocaleDateString()
                        this.http.post('/teacher/saveAddTeacher', this.qs.parse(this.teacher)).then(res => {
                            if (res) {
                                this.$Message.success('添加成功！');
                                this.modal.addTeacherFlag = false;
                                this.loading = false;
                            }
                        })
                    } else {
                        this.$Message.error('不允许存在空值!');
                    }
                })
            },
            cancel() {

            },
        },
        created() {

        }
    }
</script>

<style scoped>
    .myform {
        width: 280px;
    }
</style>
